<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"                               
                xmlns:composite="http://java.sun.com/jsf/composite">
    <composite:interface>
        <!--composite:attribute name="outcomeList" type="java.lang.String"/-->
        <composite:attribute name="pageHelper" type="org.deltaset.faces.PageHelper"/>
        <composite:attribute name="pageParamName" type="java.lang.String"/>
        <composite:attribute name="parentIdParamName" type="java.lang.String"/>
        <composite:attribute name="parentId" type="java.lang.String"/>
        <composite:attribute name="showPager"/><!-- top, bottom, both-->
        <composite:attribute name="ajaxMode" default="true"/>
        <composite:attribute name="infoMode" default="item"/><!-- item, page -->
        <composite:attribute name="msgPrevious"/>
        <composite:attribute name="msgNext"/>
        <composite:attribute name="msgPageOf"/>
        <composite:attribute name="msgItemOf"/>
        <composite:attribute name="msgNoRecords"/>
        <composite:attribute name="openRowButtonId" required="true"/>
        <composite:attribute name="id"/>
        <composite:facet name="header"/>
        <composite:facet name="row"/>
        <composite:facet name="detail"/>        
        <composite:attribute name="cols"/>
        <composite:attribute name="title"/>        

        <!-- params should be carefully documented.. it is using the EL deffered execution..
                the 'item' variable is hardcoded. the 'params' is executed in the
                context of ui:repeat over the 'items' variable.. -->
        <!-- strange but 'required' doesn't work.. -->
        <!-- the usage of f:ajax is not possible inside h:commandButton,
             when the button is inside ui:repeat,
             probably will not be possible if there is h:dataTable
             could be used in c:forEach the problem is with the time during which
             ui:repeat and c:forEach are executed (runtime vs. creation time of the tree)
        -->

    </composite:interface>

    <composite:implementation>
        <c:set var="showPager" value="#{cc.attrs.showPager}"/>
        <c:if test="#{empty cc.attrs.showPager}">
            <c:set var="showPager" value="#{deltasetConfig['showPager']}"/>
        </c:if>
        <c:set var="msgPrevious" value="#{cc.attrs.msgPrevious}"/>
        <c:if test="#{empty cc.attrs.msgPrevious}">
            <c:set var="msgPrevious" value="#{deltasetMessages['deltaset.crud.previous']}"/>
        </c:if>
        <c:set var="msgNext" value="#{cc.attrs.msgNext}"/>
        <c:if test="#{empty cc.attrs.msgNext}">
            <c:set var="msgNext" value="#{deltasetMessages['deltaset.crud.next']}"/>
        </c:if>
        <c:set var="msgPageOf" value="#{cc.attrs.msgPageOf}"/>
        <c:if test="#{empty cc.attrs.msgPageOf}">
            <c:set var="msgPageOf" value="#{deltasetMessages['deltaset.crud.pageOf']}"/>
        </c:if>
        <c:set var="msgItemOf" value="#{cc.attrs.msgItemOf}"/>
        <c:if test="#{empty cc.attrs.msgItemOf}">
            <c:set var="msgItemOf" value="#{deltasetMessages['deltaset.crud.itemOf']}"/>
        </c:if>
        <c:set var="msgNoRecords" value="#{cc.attrs.msgNoRecords}"/>
        <c:if test="#{empty cc.attrs.msgNoRecords}">
            <c:set var="msgNoRecords" value="#{deltasetMessages['deltaset.crud.norecords']}"/>
        </c:if>

        <ui:decorate template="internal/pager.xhtml">
            <ui:param name="pageHelper" value="#{cc.attrs.pageHelper}"/>
            <ui:param name="pageParamName" value="#{cc.attrs.pageParamName}"/>
            <ui:param name="parentIdParamName" value="#{cc.attrs.parentIdParamName}"/>
            <ui:param name="parentId" value="#{cc.attrs.parentId}"/>
            <ui:param name="showPager" value="#{showPager}"/>
            <ui:param name="title" value="#{cc.attrs.title}"/>
            <ui:param name="ajaxMode" value="#{cc.attrs.ajaxMode}"/>
            <ui:param name="infoMode" value="#{cc.attrs.infoMode}"/>
            <ui:param name="msgPrevious" value="#{msgPrevious}"/>
            <ui:param name="msgNext" value="#{msgNext}"/>
            <ui:param name="msgPageOf" value="#{msgPageOf}"/>
            <ui:param name="msgItemOf" value="#{msgItemOf}"/>
            <ui:param name="msgNoRecords" value="#{msgNoRecords}"/>            

            <c:set var="tableCols" value="#{cc.attrs.cols+1}"/>
            <table id="#{cc.clientId}-table" border="0" width="100%" cellpadding="0" cellspacing="0" class="ds-grid-content ui-widget-content">
                <thead>
                    <tr>                        
                <composite:renderFacet name="header" />
                <th>&#160;</th>
                </tr>
                </thead>
                <ui:repeat value="#{cc.attrs.pageHelper.items}" var="item" varStatus="status">
                    <tr id="#{component.clientId}"  class="ds-grid-row" onclick="document.getElementById(this.id+':#{cc.attrs.openRowButtonId}').onclick();deltaset.accordionDetailRow(this);">
                    <composite:renderFacet name="row"/>
                    <td class="opener" title="#{status}">
                        <!-- status=#{status} -->
                        <!-- open #{component.clientId} -->
                    </td>
                    </tr>
                    <tr style="display:none" class="ds-grid-detail-row">
                        <td colspan="#{tableCols}">
                    <composite:insertChildren/>                    
                    </td>
                    </tr>
                </ui:repeat>
            </table>
        </ui:decorate>       
        <script type="text/javascript">jQuery(deltaset.decorateDsGrid('#{cc.clientId}-table'));</script>
    </composite:implementation>
</ui:composition>